<?php
header('Access-Control-Allow-Origin: *');

require_once "WxPay.Api.php";
require_once "WxPay.Data.php";

// $re = WxPayApi::notify(function($result){

// },$msg);

// if($re == false){

// }
// echo 'SUCCESS';


$WenJian = './notify.txt';
// @chmod($WenJian, 0777);
// $req = json_encode($_REQUEST);
// file_put_contents($WenJian,$req);

$time = time();
$testxml  = file_get_contents("php://input");  //接收微信发送的支付成功信息
$result = XMLDataParse($testxml);

file_put_contents($WenJian, json_encode($result)."\r\n", FILE_APPEND); //将信息写入txt文件做支付备份
file_put_contents('D:\webroot\xianyijie\JK\weixin.txt',$testxml);



// 
// 验签
$wxnotify = new WxPayResults();
$wxnotify->values = $result;//json_decode('{"appid":"wx8b94b415ad10a96d","bank_type":"CFT","cash_fee":"1","fee_type":"CNY","is_subscribe":"N","mch_id":"1516233281","nonce_str":"aa9ilg5rjchxeqayrq4r1qd2xtj8gkwy","openid":"oP6Aa0v7Ji243HZJCOCe-t1LYeEc","out_trade_no":"20181026111227","result_code":"SUCCESS","return_code":"SUCCESS","sign":"1276E755F5C5127BD5D47F3664A50984","time_end":"20181026111235","total_fee":"1","trade_type":"APP","transaction_id":"4200000189201810261986332497"}',true);

$sign = $wxnotify->MakeSign();
$getsign = $wxnotify->GetSign();
if($sign == $getsign){

}
// 验签结束

var_dump($sign);
echo "<br>";
var_dump($getsign);

if($result['result'] == "SUCCESS"){
	
}


	// $a = ['id'=>1];
	// foreach ($a as $key => $value) {
	// 	$value['id'];
	// }

	// $a = [
	// 	['id'=>1],
	// ]

	// foreach ($a as $key => $value) {
	// 	$value['id'];
	// }
 function XMLDataParse($data){

  $xml = simplexml_load_string($data,NULL,LIBXML_NOCDATA);

  $array=json_decode(json_encode($xml),true);

  return $array;

 }

?>